import {createRouter, createWebHistory, RouteRecordRaw} from "vue-router";
import remainingRoutes from "@/router/modules/remainging";
import {App} from "vue";

const router = createRouter({
    history: createWebHistory(),
    strict: true,
    routes: remainingRoutes as RouteRecordRaw[],
    scrollBehavior: () => ({ left: 0, top: 0 }),
})

export const resetRouter = () => {
    const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root']
    router.getRoutes().forEach((route) => {
        const {name} = route
        if (name && !resetWhiteNameList.includes(name as string)) {
            router.hasRoute(name) && router.removeRoute(name)
        }
    })
}

export const setupRouter = (app: App<Element>) => {
    app.use(router)
}

export default router